package org.funsciencewithyourcomputer.client;

public class Score {

	volatile int score = 0;

	volatile int level = 1;

	volatile boolean gameOver;

	volatile long timeLevelEnd;

	volatile float speed = 10;

	Lifecycle life;
	
	Words words;

	public Score(Lifecycle life, Words words) {
		this.life = life;
		this.words = words;
	}

	public void add(String letters, int count) {
		score += count * count;
	}

	public int getScore() {
		return life.mode == Lifecycle.MODE_ORIGINAL ? words.countLetters() : score;
	}

	public int getLevel() {
		return level;
	}

	public void increaseLevel() {
		level++;
		if (speed > 30)
			speed -= 5;
		else if (speed > 5)
			speed -= 1;
		else
			speed -= 0.3;
		if (speed < 3)
			speed = 3;
	}

	public int getSpeed() {
		return (int) speed * 1000;
	}

	public void setGameOver() {
		gameOver = true;
	}

	public boolean isGameOver() {
		return gameOver;
	}

	public void setTimeLevelEnd(long timeLevelEnd) {
		this.timeLevelEnd = timeLevelEnd;
	}

	public int getTimeLeft() {
		return (int) ((timeLevelEnd - System.currentTimeMillis()) / 1000);
	}

	public void pause() {
		score = 0;
	}

	public String getText() {
		if (life.mode == Lifecycle.MODE_ACTION) {
			if (isGameOver())
				return NLS.get(NLS.GAME_OVER, new Object[] { getScore() });
			else
				return NLS.get(NLS.GAME_STATUS, new Object[] { getScore(),
						getTimeLeft() });
		}
		if (life.mode == Lifecycle.MODE_ORIGINAL) {
			int score = words.countLetters();
			if (isGameOver())
				return NLS.get(NLS.GAME_OVER_ORIGINAL, new Object[] { score});
			else
				return NLS.get(NLS.GAME_STATUS_ORIGINAL, new Object[] { score});
		}
		return null;
	}
}
